package com.guaika.reggie.controller;

import com.guaika.reggie.common.ResultMessage;
import com.guaika.reggie.common.StringChars;
import com.guaika.reggie.dto.PermissionsDto;
import com.guaika.reggie.entity.Permissions;
import com.guaika.reggie.entity.TreeMenu;
import com.guaika.reggie.service.PermissionsService;
import com.guaika.reggie.utils.TreeMenuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author GuaiKa
 */
@RestController
@RequestMapping("/permissions")
public class PermissionsController {

    @Autowired
    private PermissionsService permissionsService;

    @Autowired
    private TreeMenuUtils treeMenuUtils;

    /***
     * 根据用户查询权限
     * @param empId
     * @return
     */
    @GetMapping("/user")
    public ResultMessage<List<Permissions>> userPermissions(Long empId){
        return permissionsService.userPermissions(empId);
    }

    /***
     * 获取所有的 树形菜单
     * @return
     */
    @GetMapping("/allPermissions")
    public ResultMessage<List<TreeMenu>> allPermissions(){
        return ResultMessage.success(TreeMenuUtils.getAllMenus());
    }

    /***
     * 保存权限
     * @param permissionsDto
     * @return
     */
    @PostMapping
    public ResultMessage<String> savePermissions(@RequestBody PermissionsDto permissionsDto){
        return permissionsService.savePermissions(permissionsDto);
    }
}
